package cn.onekit;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import cn.onekit.android.ACTIVITY;

public class CONFIG {

	/**
	 * set 用户配置
	 * 
	 * @param key
	 *            键值
	 * @param Value
	 *            数据
	 */
	public static void set(String key, Object Value) {
		set(ACTIVITY.context, key, Value);
	}

	public static void set(Context context, String key, Object Value) {
		// OneKit.init();
		SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(context);
		Editor edit = spf.edit();
		edit.putString(key, Value != null ? Value.toString() : null);
		edit.commit();
	}

	/**
	 * set 获取配置
	 * 
	 * @param key
	 *            键值
	 */
	public static Object get(String key) {
		return get(ACTIVITY.context, key);
	}

	public static Object get(Context context, String key) {

		// OneKit.init();
		SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(context);
		return spf.getString(key, null);
	}
	/*
	 * public static JSONObject getObject(String key) {
	 * 
	 * OneKit.init(); try { return new JSONObject(get(key)); } catch
	 * (JSONException e) { DIALOG.warning(true, e); return null; } } public
	 * static JSONArray getArray(String key) {
	 * 
	 * OneKit.init(); try { return new JSONArray(get(key)); } catch
	 * (JSONException e) { DIALOG.warning(e); return null; } }
	 */

	@SuppressWarnings("unused")
	private static void clearData() {
		// OneKit.init();
		SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(ACTIVITY.context);
		spf.edit().clear().commit();
	}
}
